package org.mebusw.struts.vo;

import java.io.Serializable;

import org.mebusw.struts.davincicode.CardHand;
import org.mebusw.struts.davincicode.CardPool;

public class GameTable implements Serializable {
	private static final int INIT_SET_FOR_2__C = 4;
	private int gid;
	private static final int MAX_PLAYERS__C = 4;
	private String players[] = new String[MAX_PLAYERS__C];
	private CardHand cardHands[] = new CardHand[MAX_PLAYERS__C];
	private boolean guessDisable;
	private boolean takeDisable;
	private boolean finishDisable;
	/** how many players in total */
	private int playerCount;
	/** whose turn is it now? */
	private int currPlayer;
	private CardHand cardHand;
	private CardPool cardPool = new CardPool();

	public GameTable() {

	}

	public void init(int playerCount, String p1, String p2, String p3, String p4) {
		System.out.println("GameTable.init()");

		switch (playerCount) {
		case 2:
			setPlayerCount(2);
			setCurrPlayer(0);
			players[0] = p1;
			players[1] = p2;
			for (int i = 0; i < playerCount; i++) {
				cardHands[i] = new CardHand();
				for (int j = 0; j < INIT_SET_FOR_2__C; j++) {
					cardHands[i].insertSort(getCardPool().randTake());
				}
			}
			break;
		default:
			break;
		}

	}

	public int getPlayerId(String username) {
		for (int i = 0; i < getPlayerCount(); i++) {
			if (getPlayers()[i].equals(username))
				return i;
		}
		return -1;

	}

	public CardHand getCardHand() {
		return this.cardHand;
	}

	public CardPool getCardPool() {
		return this.cardPool;
	}

	public void setCardPool(CardPool cardPool) {
		this.cardPool = cardPool;
	}

	public void setCardHand(CardHand cardHand) {
		this.cardHand = cardHand;
	}

	public boolean isTakeDisable() {
		return takeDisable;
	}

	public void setTakeDisable(boolean takeDisable) {
		System.out.println("GameTable.setTakeDisable()");
		this.takeDisable = takeDisable;
	}

	public boolean isFinishDisable() {
		return finishDisable;
	}

	public void setFinishDisable(boolean finishDisable) {
		this.finishDisable = finishDisable;
	}

	public boolean isGuessDisable() {
		return guessDisable;
	}

	public void setGuessDisable(boolean guessDisable) {
		this.guessDisable = guessDisable;
	}

	public String[] getPlayers() {
		return players;
	}

	public void setPlayers(String[] players) {
		this.players = players;
	}

	public CardHand[] getCardHands() {
		return cardHands;
	}

	public void setCardHands(CardHand[] cardHands) {
		this.cardHands = cardHands;
	}

	public int getGid() {
		return gid;
	}

	public void setGid(int gid) {
		this.gid = gid;
	}

	public int getPlayerCount() {
		return playerCount;
	}

	public void setPlayerCount(int playerNbr) {
		this.playerCount = playerNbr;
	}

	public int getCurrPlayer() {
		return currPlayer;
	}

	public void setCurrPlayer(int currPlayer) {
		this.currPlayer = currPlayer;
	}

}
